package com.itheima.article.controller;

import com.itheima.article.pojo.ApAuthor;
import com.itheima.article.service.ApAuthorService;
import com.itheima.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.article.controller
 */
@RestController
public class ApiController {

    @Autowired
    private ApAuthorService apAuthorService;

    /**
     * 通过app端用户id与自媒体id查询作者信息
     * @param apUserId
     * @return
     */
    @GetMapping("/api/apAuthor/getByApUserIdWmUserId/{apUserId}/{wmUserId}")
    public ResultVo<ApAuthor> getByApUserIdWmUserId(@PathVariable(value = "apUserId") Long apUserId,
                                             @PathVariable(value = "wmUserId") Long wmUserId){
        ApAuthor apAuthor =apAuthorService.getByApUserIdWmUserId(apUserId, wmUserId);
        return ResultVo.ok(apAuthor);
    }

    /**
     * 添加作者账号
     */
    @PostMapping("/api/apAuthor/add")
    public ResultVo add(@RequestBody ApAuthor apAuthor){
        if (apAuthorService.save(apAuthor)) {
            return ResultVo.ok();
        }
        return ResultVo.error();
    }
}
